
"""
Created on Tue Feb 19 14:55:43 2013

@author: aponteeduarddo@gmail.com
Copyright Eduardo Aponte 2013.
"""

from mex_binder import binder_py

eyelink_get_sample = binder_py('mx_eyelink_get_sample')
eyelink_get_sample.mx_c.headers = ['<eyelink.h>','"mex.h"','"utils.h"']
eyelink_get_sample.bindo += ['utils.o']
eyelink_get_sample.mx_c.code = \
"""
INT16 _main( mxArray *ima )
{   
    ISAMPLE is;
    INT16 s;
    s = eyelink_get_sample( void, &is ) ;
    if ( s ){
        isample2struc( is, ima )
    } 
    return s;
}

void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    double *status;
    mwSize td[2] = {1,1};
        
    /* Verify input arguments. */
    if(nrhs != 0 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 2 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
    
    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status = mxGetPr(plhs[0]);
    if ( nlhs == 1){
        void FARTYPE *isample;
        *status = (double ) eyelink_get_sample( isample );
    }
    *status = (double ) _main( plhs[1] );  
    return;
}
"""

eyelink_get_sample.mx_c.mdoc = \
"""function [ ] = mx_eyelink_get_sample( )
%MX_EYELINK_GET_SAMPLE Gets an integer (unconverted) sample from end of queue,
% discards any events encountered.
%
% Returns:
% 0 if no data. 1 if data retrieved.
% sample 	Pointer to buffer (ISAMPLE or ALL_DATA type).
%
%
%    UINT32      time;           /*!< time of sample */
%    INT16       type;           /*!< always SAMPLE_TYPE */
%    UINT16      flags;          /*!< flags to indicate contents */
%    INT16       px[2];                  /*!< pupil x */
%    INT16       py[2];                  /*!< pupil y */
%    INT16       hx[2];                  /*!< headref x */
%    INT16       hy[2];                  /*!< headref y */
%    UINT16      pa[2];          /*!< pupil size or area */
%    INT16       gx[2];                  /*!< screen gaze x */
%    INT16       gy[2];                  /*!< screen gaze y */
%    INT16       rx;                             /*!< screen pixels per degree */
%    INT16       ry;             /*!< screen pixels per degree */
%    UINT16      status;         /*!< tracker status flags    */
%    UINT16      input;          /*!< extra (input word)      */
%    UINT16      buttons;        /*!< button state & changes  */
%    INT16       htype;          /*!< head-tracker data type (0=none) */
%    INT16  hdata[8];        /*!< head-tracker data */
%
"""
eyelink_get_sample.write_c()
eyelink_get_sample.write_m()
eyelink_get_sample.compile()
eyelink_get_sample.write_sh()

